const { staff_collection, staff_log } = require('../config')
const pick = require('lodash/pick')
const { db } = require('../config')
const { command } = require('../config')
const common = require('./common');
const _ = command
exports.main = async (event, context) => {
  const userInfo = event.userInfo;
  // 根据筛选条件查询员工
  const { newGrid, oldGrid, handler, account, zwname } = event;

  try {
    info = await db.collection(staff_collection).where({
      account: account,
    }).update({
      grid: newGrid
    })

    res = await db.collection(staff_log).add({
      handlerName: userInfo.name,
      handlerAccount: userInfo.account,
      newData: JSON.stringify({ grid: newGrid }),
      oldData: JSON.stringify({ grid: oldGrid }),
      zwname,
      zwaccount: account,
      updateTime: common.getDateTime(),
    })

    return {
      code: 0,
      info,
      msg: '',
    }

  } catch (error) {
    return {
      code: -1,
      info: null,
      msg: error,
    }
  }
}
